[CakePHP] I am so confused. What should I write in the default.ctp

Posted by kwokwai on Stack Overflow See other posts from Stack Overflow or by kwokwai
Published on 2010-05-14T13:48:14Z Indexed on 2010/05/14 13:54 UTC
Read the original article Hit count: 228

Filed under:

Hi all, I am learning cakePHP, everything seems alright except that I am very confused of
how to make use of the default.ctp and what should be put inside the Elements folder.

Here is the default.ctp file that I have been using since my very first lesson on learning cakePHP:
(I copied from this URL http://book.cakephp.org/view/96/Layouts)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title_for_layout?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Include external files and scripts here (See HTML helper for more info.) -->
<?php echo $scripts_for_layout ?>
</head>
<body>

<!-- If you'd like some sort of menu to 
show up on all of your views, include it here -->
<div id="header">
    <div id="menu">...</div>
</div>

<!-- Here's where I want my views to be displayed -->
<?php echo $content_for_layout ?>

<!-- Add a footer to each displayed page -->
<div id="footer">...</div>

</body>
</html>

But the problem is that the layout will take effect to all web pages that I have created.
Let's see the case that I have recently encountered.
In one of the .ctp files, I need to use JQuery function
and I need to ass some and tags in the .ctp file. Here are the and tags I used:

<Script language="javascript">
$(document).ready(function()
{
// some functions here
});
</Script>

<style type="text/css">
{
#toppage{
 width:800px;
}

But when I followed the default.ctp file,
I noticed that these tags (i.e. and ) happened to appear below the tag.
As far as I know, the and self-defined Javascript functions
should be put inside the tag of the HTML instead.
I have considered to add the and in the default.ctp file,
but then these codes would appear in every web pages instead of just a particular web page.

Please help.

© Stack Overflow or respective owner

Related posts about cakephp